<template>
  <div>
    <el-dialog
      title="红包领取详情"
      v-model="other.isShow"
      lock-scroll
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      draggable
      align-center
      width="1000px"
      @closed="closed"
    >
      <div class="redpack-detail-dialog-box">
        <div class="grow-[1] h-0 overflow-hidden">
          <el-table
            scrollbar-always-on
            ref="elTableRef"
            v-loading="state.loading"
            :data="list"
            height="100%"
            border
            stripe
            fit
          >
            <template #empty>
              <ui-empty />
            </template>
            <el-table-column
              prop="Name"
              align="center"
              label="用户名"
              show-overflow-tooltip
              min-width="80"
            />
            <el-table-column prop="Nickname" align="center" label="昵称" show-overflow-tooltip />
            <el-table-column prop="Note" align="center" label="备注" show-overflow-tooltip />
            <el-table-column prop="Amount" align="center" label="领取金额">
              <template #default="{ row }: TableItem">
                <ui-amount :num="row.Amount"></ui-amount>
              </template>
            </el-table-column>
            <el-table-column prop="CreatedAt" align="center" label="领取时间">
              <template #default="{ row }: TableItem">
                {{ formatDate(row.CreatedAt) }}
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div class="flex justify-end mt-[10px] mx-[15px]">
          <ui-pagination
            :total="state.total"
            v-model:pageSize="state.pageSize"
            v-model:currentPage="state.page"
            @current-change="getData"
          ></ui-pagination>
        </div>
      </div>
    </el-dialog>
  </div>
</template>
<script setup lang="ts">
import { useList } from "@/hooks/useList";
import { reqReportHongbaoDetail } from "@/api/report";
import { formatDate } from "@/utils/common";

interface TableItem {
  row: ReportHongbaoDetailMo;
}
interface Params {
  Id: number;
}
const props = withDefaults(
  defineProps<{
    id: number | undefined;
  }>(),
  {
    id: undefined
  }
);
const emit = defineEmits(["update"]);

const other = reactive({
  updating: false,
  isShow: false
});
const getParams = () => {
  const params: Params = {
    Id: props.id as number
  };
  return params;
};
const { elTableRef, state, list, getData } = useList<ReportHongbaoDetailMo, Params>(
  reqReportHongbaoDetail,
  getParams
);

const closed = () => {
  other.isShow = false;
};

const open = () => {
  if (!props.id) return;
  other.isShow = true;
  getData();
};

defineExpose({
  open
});
</script>
<style scoped lang="scss">
.redpack-detail-dialog-box {
  width: 100%;
  height: 500px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
:deep(.el-table) td .cell {
  padding: 0px 5px !important;
}
</style>
